package com.zegome.uis;

import aurelienribon.tweenengine.TweenManager;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.InputMultiplexer;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.Matrix4;

public abstract class ZScreen implements Screen{
	protected ZGame game;
	protected ZStage stage;
	protected SpriteBatch batch;
	protected InputMultiplexer input;
	
	public ZScreen(ZGame mGame){
		game = mGame;
		final Matrix4 m = new Matrix4();
		m.setToOrtho2D(0, 0, game.getDefWidth() , game.getDefHeight());		
		batch = new SpriteBatch();
		batch.setProjectionMatrix(m);
		stage = new ZStage(game.getDefWidth() , game.getDefHeight(),true);
		((OrthographicCamera)stage.getCamera()).setToOrtho(false, game.getDefWidth() , game.getDefHeight());
		input = new InputMultiplexer();
		input.addProcessor(stage);
		Gdx.input.setInputProcessor(input);
	}
	
	abstract public void update(float delta);
	abstract public void draw();
	
	@Override
	public void render(float delta) {
		Gdx.gl.glClearColor(1, 1, 1, 1);
		Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
		update(delta);
		stage.act(delta);
		batch.begin();
		draw();
		batch.end();
		stage.draw();
	}
	
	public TweenManager getManager(){
		return stage.getManager();
	}
	
	@Override
	public void dispose() {
		stage.dispose();
		batch.dispose();
	}
}
